﻿using System.Windows;
using RAD.Modules.Scripts.Interfaces;
using RAD.Modules.Scripts.Models;
using RAD.Modules.Scripts.PresentationModels;

namespace RAD.Modules.Scripts.Views
{
    /// <summary>
    /// Interaction logic for ParamsSelectDialog.xaml
    /// </summary>
    public partial class ParamsSelectDialog : Window, IParamsSelectDialog
    {
        private ParamsPresentationModel _model;

        public ParamsSelectDialog()
        {
            Owner = Application.Current.MainWindow;
            InitializeComponent();
            _model = new ParamsPresentationModel();
        }

        #region IParamsSelectDialog Members

        public Window Dialog
        {
            get { return this; }
        }

        public ParamsPresentationModel Model
        {
            get { return _model; }
        }

        #endregion

        private void _okBtn_Click(object sender, RoutedEventArgs e)
        {
            _model.Computer = _computer.Text;
            _model.Share = _share.Text;
            _model.UserName = _user.Text;

            if (radioButton1.IsChecked.Value)
                _model.AccessLevel = AccessLevel.Read;
            else if (radioButton2.IsChecked.Value)
                _model.AccessLevel = AccessLevel.Write;
            else
                _model.AccessLevel = AccessLevel.Full;

            _model.UserGroup = radioButton4.IsChecked.Value;

            if (radioButton6.IsChecked.Value)
                _model.PermissionType = PermissionType.Add;
            else if (radioButton7.IsChecked.Value)
                _model.PermissionType = PermissionType.Delete;
            else
                _model.PermissionType = PermissionType.Change;


            // TODO: Перед тем как закрыть диалог необходимо проверить все ли элементы заполнены правильно.          
            DialogResult = true;
        }

        private void _cancelBtn_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
    }
}